/*    */ package net.sourceforge.appgen.support;
/*    */ 
/*    */ import java.util.List;
/*    */ import net.sourceforge.appgen.model.Entity;
/*    */ import net.sourceforge.appgen.model.Field;
/*    */ import org.eclipse.jface.viewers.CellEditor;
/*    */ import org.eclipse.jface.viewers.ColumnViewer;
/*    */ import org.eclipse.jface.viewers.EditingSupport;
/*    */ import org.eclipse.jface.viewers.TableViewer;
/*    */ import org.eclipse.jface.viewers.TextCellEditor;
/*    */ 
/*    */ public class FieldPkPositionEditingSupport extends EditingSupport
/*    */ {
/*    */   private CellEditor editor;
/*    */ 
/*    */   public FieldPkPositionEditingSupport(ColumnViewer viewer)
/*    */   {
/* 39 */     super(viewer);
/*    */ 
/* 41 */     this.editor = new TextCellEditor(((TableViewer)viewer).getTable(), 131072);
/*    */   }
/*    */ 
/*    */   protected boolean canEdit(Object element)
/*    */   {
/* 46 */     return true;
/*    */   }
/*    */ 
/*    */   protected CellEditor getCellEditor(Object element)
/*    */   {
/* 51 */     return this.editor;
/*    */   }
/*    */ 
/*    */   protected Object getValue(Object element)
/*    */   {
/* 56 */     Field field = (Field)element;
/*    */ 
/* 58 */     return field.getPkPosition() <= 0 ? "" : String.valueOf(field.getPkPosition());
/*    */   }
/*    */ 
/*    */   protected void setValue(Object element, Object value)
/*    */   {
/* 63 */     Field field = (Field)element;
/*    */ 
/* 65 */     if ((value == null) || (String.valueOf(value).length() == 0)) {
/* 66 */       field.setPkPosition(0);
/*    */     }
/*    */     try
/*    */     {
/* 70 */       int pkPosition = Integer.parseInt(String.valueOf(value));
/*    */ 
/* 74 */       if (pkPosition < 0) {
/* 75 */         return;
/*    */       }
/* 77 */       if (pkPosition > 0) {
/* 78 */         Entity entity = field.getEntity();
/* 79 */         if (field.getEntity() != null) {
/* 80 */           List<Field> fieldList = entity.getFieldList();
/* 81 */           if (fieldList != null) {
/* 82 */             for (Field f : fieldList) {
/* 83 */               int p = f.getPkPosition();
/* 84 */               if ((!field.equals(f)) && (p == pkPosition)) {
/* 85 */                 return;
/*    */               }
/*    */             }
/*    */           }
/*    */         }
/*    */       }
/*    */ 
/* 92 */       field.setPkPosition(pkPosition);
/*    */     }
/*    */     catch (NumberFormatException localNumberFormatException) {
/*    */     }
/* 96 */     getViewer().update(element, null);
/*    */   }
/*    */ }

/* Location:           C:\Users\lzl6066\Downloads\net.sourceforge.appgen_1.2.0\plugins\net.sourceforge.appgen_1.2.0.201002031718\
 * Qualified Name:     net.sourceforge.appgen.support.FieldPkPositionEditingSupport
 * JD-Core Version:    0.6.0
 */